package com.egg.ylt.presenter.impl;

import com.egg.ylt.Utils.API;
import com.egg.ylt.pojo.GetEquipmentsEntity;
import com.egg.ylt.presenter.IDevicePresenter;
import com.egg.ylt.view.IDeviceView;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.CommonUtils;
import com.yonyou.framework.library.mvp.impl.BasePresenter;
import com.yonyou.framework.library.net.ReqCallBack;
import com.yonyou.framework.library.net.RequestManager;

import java.util.HashMap;

/**
 * sichaoqi on 2018/12/14
 */
public class DevicePresenterImpl extends BasePresenter<IDeviceView> implements IDevicePresenter {
    @Override
    public void postDeviceData(String token, String companyId, String pageSize, String pageNum) {
        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        hashMap.put("companyId", companyId);
        hashMap.put("pageSize", pageSize);
        hashMap.put("pageNum", pageNum);
        RequestManager.getInstance().requestPostByAsyn(API.POST_EQUIPMENTS, hashMap, new ReqCallBack<GetEquipmentsEntity>() {

            @Override
            public void onReqSuccess(GetEquipmentsEntity result) {
                mView.dismissDialogLoading();
                mView.getDeviceData(result);
            }

            @Override
            public void onFailure(String result) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, result, false);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, error.getMsg(), false);
            }
        });
    }

    @Override
    public void deleteDevice(String token, String ids) {
        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        hashMap.put("ids", ids);
        RequestManager.getInstance().requestPostByAsyn(API.POST_DELETE_EQUIPMENT, hashMap, new ReqCallBack<String>() {

            @Override
            public void onReqSuccess(String result) {
                mView.dismissDialogLoading();
                mView.deleteDeviceSucceed();
            }

            @Override
            public void onFailure(String result) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, result, false);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, error.getMsg(), false);
            }
        });
    }
}
